home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / lo-ieee.cc < prev    next >
C/C++ Source or Header  |  1997-03-07  |  3KB  |  129 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26.  
  27. #include <cfloat>
  28. #include <cmath>
  29.  
  30. #if defined (HAVE_FLOATINGPOINT_H)
  31. #include <floatingpoint.h>
  32. #endif
  33.  
  34. #if defined (HAVE_NAN_H)
  35. #if defined (SCO)
  36. #define _IEEE 1
  37. #endif
  38. #include <nan.h>
  39. #if defined (SCO)
  40. #undef _IEEE
  41. #endif
  42. #endif
  43.  
  44. #if defined (HAVE_INFINITY)
  45. extern "C" double infinity ();
  46. #endif
  47.  
  48. #if defined (HAVE_QUIET_NAN)
  49. extern "C" double quiet_nan (long);
  50. #endif
  51.  
  52. #include "lo-ieee.h"
  53.  
  54. // Octave's idea of infinity.
  55. double octave_Inf;
  56.  
  57. // Octave's idea of not a number.
  58. double octave_NaN;
  59.  
  60. void
  61. octave_ieee_init (void)
  62. {
  63. #if defined (HAVE_ISINF) || defined (HAVE_FINITE)
  64.  
  65. // Some version of gcc on some old version of Linux used to crash when
  66. // trying to make Inf and NaN.
  67.  
  68. #if defined (SCO)
  69.   double tmp = 1.0;
  70.   octave_Inf = 1.0 / (tmp - tmp);
  71. #elif defined (__alpha__)
  72.   extern unsigned int DINFINITY[2];
  73.   octave_Inf =  (*((double *) (DINFINITY)));
  74. #elif defined (HAVE_INFINITY)
  75.   octave_Inf = infinity ();
  76. #elif defined (linux)
  77.   octave_Inf = HUGE_VAL;
  78. #else
  79.   double tmp = 1e+10;
  80.   octave_Inf = tmp;
  81.   for (;;)
  82.     {
  83.       octave_Inf *= 1e+10;
  84.       if (octave_Inf == tmp)
  85.     break;
  86.       tmp = octave_Inf;
  87.     }
  88. #endif
  89.  
  90. #endif
  91.  
  92. #if defined (HAVE_ISNAN)
  93.  
  94. #if defined (linux)
  95.   octave_NaN = NAN;
  96. #elif defined (__alpha__)
  97.   extern unsigned int DQNAN[2];
  98.   octave_NaN = (*((double *) (DQNAN)));
  99. #elif defined (HAVE_QUIET_NAN)
  100.   octave_NaN = quiet_nan (0L);
  101. #else
  102.   octave_NaN = octave_Inf / octave_Inf;
  103. #endif
  104.  
  105. #endif
  106. }
  107.  
  108. #if defined (SCO)
  109.  
  110. extern "C" int
  111. isnan (double x)
  112. {
  113.   return (IsNANorINF (x) && NaN (x) && ! IsINF (x)) ? 1 : 0;
  114. }
  115.  
  116. extern "C" int
  117. isinf (double x)
  118. {
  119.   return (IsNANorINF (x) && IsINF (x)) ? 1 : 0;
  120. }
  121.  
  122. #endif
  123.  
  124. /*
  125. ;;; Local Variables: ***
  126. ;;; mode: C++ ***
  127. ;;; End: ***
  128. */
  129.